package xyz.yuanjilu.service.impl;

import java.net.URL;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import xyz.yuanjilu.service.SystemInfo;
import xyz.yuanjilu.utils.ThreadUtils;
/**
 * 在系统启动时，打印相关系统信息
 * @author kkomge@qq.com
 */
@Component
public class SystemInfoImpl implements SystemInfo {
	Logger logger= LoggerFactory.getLogger(getClass());
	/* (non-Javadoc)
	 * @see xyz.yuanjilu.service.impl.SystemInfo#init()
	 */
	@Override
	@PostConstruct
	public void init(){
		showClassLaderInfo();
		showJVMTreadsTrace();
	}
	/* (non-Javadoc)
	 * @see xyz.yuanjilu.service.impl.SystemInfo#showClassLaderInfo()
	 */
	@Override
	public void showClassLaderInfo(){
		ClassLoader loader = getClass().getClassLoader();
		logger.info("----------------打印加载的classLoader----------------");
		while(loader != null) {  
          	logger.info(loader.getClass().getName());  
            loader = loader.getParent();  
        }
		
		URL[] urls = sun.misc.Launcher.getBootstrapClassPath().getURLs();  
		logger.info("加载JDK or JRE信息");
		for (int i = 0; i < urls.length; i++) {  
			logger.info(""+urls[i].toExternalForm());  
		}
		logger.info("sun.boot.class.path : "+System.getProperty("sun.boot.class.path"));
	}
	/* (non-Javadoc)
	 * @see xyz.yuanjilu.service.impl.SystemInfo#showJVMTreadsTrace()
	 */
	@Override
	public void showJVMTreadsTrace(){
		logger.info("----------------打印JVM线程信息----------------");
		ThreadUtils.showJVMTreadsTrace();
	}
}
